/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#ifndef PARSEALL_H
#define PARSEALL_H

#include <Windows.h>
#include <tchar.h>
#include <string>
#include <list>
#include <smtptr.h>
#include "parse.h"
#include "parsenode.h"
#include "tokerr.h"

using namespace std;

/////////////////////////////////////////////////////////////////////
// ParseAll: A super-set of the parse. Goes foward, and backwards
//           to the buffer
/////////////////////////////////////////////////////////////////////
class ParseAll
{
public: // Construction
	ParseAll() {}

	ParseAll(const ParseAll& rhs)
	{
		Copy(rhs);
	}

public: // Methods
	void InitBuffer(const wchar_t *buffer); // Initilizes buffer

	void InitDelim(const wchar_t *delim = PARSE_DELIM) // Initializes deliminators
	{
		_parse->InitDelim();
	}
	
	void InitComment(wchar_t com = ';') // Initializes comment character
	{
		_parse->InitComment(com);
	}

public: // Methods
	TokErr Prev(); // Gets previous word
	TokErr Next(); // Gets next word

public: // Methods
	void Reset(); // Resets the class

public: // Accessor methods
	wstring GetBuffer() { return _parse->GetBuffer(); }
	wstring GetWord() { return _i->word; }
	wstring GetDelim() { return _parse->GetDelim(); }
	wchar_t GetComment() { return _parse->GetComment(); }

	bool IsBegin() const { return _i->is_begin; }
	bool IsEnd() const { return _i->is_end; }
	
	bool IsString() const { return _i->is_string; }

public: // Operators
	ParseAll& operator = (const ParseAll& rhs)
	{
		Copy(rhs);
		return *this;
	}
private: // Methods
	void Copy(const ParseAll& rhs); // Copies the class

private: // Attributes
	SmtPtr<Parse> _parse; // Back-end parser
	list<ParseNode> _list_words; // The words
	list<ParseNode>::iterator _i; // A word in the buffer
};
#endif